#include "DerivationTree.h"
#include "Variable.h"

VariableNode::VariableNode() : NodeTree_CRTP<VariableNode>() { }

VariableNode::VariableNode(char* number, unsigned int _length) : NodeTree_CRTP<VariableNode>(), buffer(number), length(_length) { }

VariableNode::VariableNode(const VariableNode& copy) : NodeTree_CRTP<VariableNode>(copy) {
	length = copy.length;
	buffer = new char[length];
	for (unsigned int i = 0; i < length; ++i) buffer[i] = copy.buffer[i];
}

std::string VariableNode :: getName() const {
	return std::string(buffer);
}

bool VariableNode :: execute(Pointer<LeonardVirtualMachine> LVM) {
	AutoPointer<TreeExpression::Expression> variable(new TreeExpression::Variable(std::string(buffer)));//TODO check for definition
	LVM->push(variable);
	return true;
}

